//
//  TitleButton.m
//  CC
//
//  Created by Calvin on 4/27/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "TitleButton.h"

@implementation TitleButton
/**
 *  @author Calvin.wang, 15-04-27 16:04:48
 *
 *  <#Description#>
 *
 *  @param frame <#frame description#>
 *
 *  @return <#return value description#>
 */
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView.contentMode = UIViewContentModeCenter;
        self.adjustsImageWhenHighlighted=NO;
        self.titleLabel.textAlignment = NSTextAlignmentRight;
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.titleLabel.font = NavigationTitleFont;
    }
    
    return self;
}

/**
 *  @author Calvin.wang, 15-04-27 16:04:44
 *
 *  setting interior image frame
 *
 *  @param contentRect <#contentRect description#>
 *
 *  @return <#return value description#>
 */
-(CGRect)imageRectForContentRect:(CGRect)contentRect
{
    CGFloat imageY=0;
    CGFloat imageW=self.frame.size.height;
    CGFloat imageH =imageW;
    CGFloat imageX = self.frame.size.width-imageW;
    return CGRectMake(imageX, imageY, imageW, imageH);
}

/**
 *  @author Calvin.wang, 15-04-27 16:04:55
 *
 *  setting interior text frame
 *
 *  @param contentRect <#contentRect description#>
 *
 *  @return <#return value description#>
 */
-(CGRect)titleRectForContentRect:(CGRect)contentRect
{
    CGFloat titleY =0;
    CGFloat titleX =0;
    CGFloat titleH =self.frame.size.height;
    CGFloat titleW = self.frame.size.width - self.frame.size.height;
    return CGRectMake(titleX, titleY, titleW, titleH);
}

-(void)setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    CGSize titleSize = [title sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.titleLabel.font,self.titleLabel.font.fontName,nil]];
    CGRect frame = self.frame;
    frame.size.width = titleSize.width*2 + frame.size.height;
    self.frame=frame;
    NSLog(@"titlesize is %@",NSStringFromCGSize(titleSize));
}
@end
